package routinePractice

import (
	"fmt"
)

type sales struct {
	name string
}

func (s sales)sell(c chan int,sw chan int)  {
	for{
		current,ok := <- c
		if !ok || current<0{

			close(sw)
			return
		}
		fmt.Printf("%v号卖了 # %v \n",s.name,current)
		c <- current - 1
	}
}

func SellTicket(input string)  {
	ticketNum := make(chan int,1)
	sw := make(chan int)
	ticketNum <- 999

	for i:=0;i<len(input) ;i++  {
		go sales{name:string(input[i])}.sell(ticketNum,sw)
	}
	<- sw
	fmt.Println("卖完啦")
}